package com.power.sifa.approve.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.approve.model.Apl_matter_attach;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 申请材料 持久层(hibernate)
 */

public interface Apl_matter_attachDao extends JpaRepository<Apl_matter_attach, Serializable>, JpaSpecificationExecutor<Apl_matter_attach>, Repository<Apl_matter_attach, Serializable>, Apl_matter_attachDaoCustom<Apl_matter_attach, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_matter_attach s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

    /**
     * 根据申请id获取申请材料列表
     * @param applyid 申请id
     * @return
     */
    @Query(value = "select * from Apl_matter_attach where applyid = :applyid and deleted = 0 order by ismanual desc,sortnum asc", nativeQuery = true)
    List<Apl_matter_attach> queryListByApplyid(String applyid);

    @Query(value = "from Apl_matter_attach where applyid = :applyid")
    List<Apl_matter_attach> queryAllListByApplyid(String applyid);

    /**
     * 根据申请id获取申请材料列表
     * @param applyid 申请id
     * @return
     */
    @Query(value = "select a.* from Apl_matter_attach a join Std_attach c on a.stdattachid = c.id where a.applyid = :applyid and c.mattype = :mattype", nativeQuery = true)
    List<Apl_matter_attach> getListByApplyid(String applyid, Integer mattype);

}
